/*
 * DIM-SUM操作系统 -- sbi 串口控制台驱动
 *
 * Copyright (C) 2023 国科础石(重庆)软件有限公司
 *
 * 作者: Lei Ding <dinglei@kernelsoft.com>
 *
 * License terms: GNU General Public License (GPL) version 3
 *
 */

#include <asm/sbi.h>
#include <dim-sum/init.h>
#include <dim-sum/errno.h>
#include <dim-sum/console.h>
#include <dim-sum/simple_console.h>

static void sbi_simple_write(struct console *con, const char *s, unsigned count)
{
	unsigned int i;

	for (i = 0; i < count; i++, s++) {
		sbi_console_putchar(*s);
	}
}

static int __init sbi_init_simple(struct simple_console_device *device, void *opt)
{
	/* 这里 0xffffffff 可以是任意不为 0 的值 */
	device->membase = (void*)0xfffffff;
	if (!device->membase)
		return -ENODEV;

	device->con->write = sbi_simple_write;

	return 0;
}

const struct simple_console_id simple_console_sbi = {
	.name  = "riscv,sbi",
	.init = sbi_init_simple,
};
